#ifndef TSB_DEVICE_DEVICE
#define TSB_DEVICE_DEVICE
/*
* 
* @license	Apache License 2.0
* @author	Eugene Kuznetsov
*
*/
#include "Base.hpp"
#include <string>

class CDataBuffer;
class CConfiguration;
class CDoubleBufferQueue;

#define MAX_TARGETSERVER_COUNT 3

class CDevice
{
public:
	CDevice(Int32 link, std::string ip_address, UInt8 port);
	virtual ~CDevice();

	// timeout in seconds
	virtual Base::eState Authorize(UInt8 timeout);
	virtual Base::eState StartTargetServers(UInt8 timeout);
	virtual Link::eConnectState Disconnect();

	virtual Link::eLinkIOState SendDataToDevice(CDataBuffer* buffer);
	virtual Link::eLinkIOState ReceiveDataFromDevice(CDataBuffer& buffer);
	virtual bool IsReadyToReceive(Base::eState& state);

	Link::eConnectState getState() const;
	Int16 getLastError();

private:
	static UInt64 FetchID(CDataBuffer* buffer, Device::eType& dev_type);

private:
	Device::eType m_eDeviceType;
	Link::eConnectState m_eState;
	std::string m_sIpAddress;
	UInt8 m_nPort;
	Int32 m_nLink;
	Int16 m_nLastError;
	UInt64 m_nID;
	bool m_bAuthorized;
	CConfiguration* m_pConfig;
	CDoubleBufferQueue* m_pBufferQueues;
};

#endif
